import EditorCore from './EditorCore';
import ShapePlugin from '../plugins/ShapePlugin';
import TextPlugin from '../plugins/TextPlugin';
import LayerPlugin from '../plugins/LayerPlugin';
import HistoryPlugin from '../plugins/HistoryPlugin';
import AIPlugin from '../plugins/AIPlugin';
import ImagePlugin from '../plugins/ImagePlugin';

/**
 * 创建并初始化编辑器实例
 * @param {HTMLCanvasElement} canvasElement - Canvas元素
 * @param {Object} options - 编辑器选项
 * @returns {EditorCore} 初始化后的编辑器实例
 */
export function createEditor(canvasElement, options = {}) {
    // 创建编辑器核心实例
    const editor = new EditorCore();
    editor.init(canvasElement, options);

    // 注册基础插件
    editor.use(ShapePlugin);
    editor.use(TextPlugin);
    editor.use(LayerPlugin);
    editor.use(HistoryPlugin);
    editor.use(ImagePlugin);

    // 如果启用了AI功能，则注册AI插件
    if (options.enableAI !== false) {
        editor.use(AIPlugin, {
            apiUrl: options.aiApiUrl || '/api/ai'
        });
    }

    return editor;
}

export { EditorCore };

// 默认导出createEditor函数
export default createEditor;
